var selectAddress;
var endAnimation = function(){
	var x = document.getElementById("addressZone");
	$(x).hide();
    x.removeEventListener("webkitAnimationEnd", endAnimation);
	
};	window.location.hash="#";
window.onload=function(){
	cityInit();

	window.onhashchange=function(){
		$('#addressZone').show();
		if(window.location.hash == '#city'){
			$('#addressZone').removeClass('move_right');
			$('#addressZone').addClass('move_left');
		}else{
			$('#addressZone').removeClass('move_left');
			$('#addressZone').addClass('move_right');
			
			var x = document.getElementById("addressZone");
            x.addEventListener("webkitAnimationEnd", endAnimation);
		};
	};
};
var selectCity = function(obj){
	if(obj){
		selectAddress = obj;
	};
	window.location.hash="city";
};
var backCiy= function(){
	window.location.hash="";
};
var chooseCity = function(e){
	var target = $(e.currentTarget);
	window.location.hash="";
	$(selectAddress).val(target.attr('data-name'));
};

/**
 * form表单
 */
seajs.use(["zui/form","zui/fightCalendar","zui/date"],function(Form,Calendar,zDate){
	var form1 = 
			new Form({srcNode:"#CM_Form",validType:"custom",validateFunc:function(ev){
				var field=ev.field;
				var msg=ev.validateMsg;
				if(msg==""){

				}else{
				  	App.showToast(msg);
			  	}
		  	}});
	var myDate = new Date();  
	var today =zDate.format(new Date(myDate.getTime()+1*24*3600*1000),"yyyy-mm-dd");
	$("#startDate").on("click",function(){
		new Calendar({
			selectedSuffix : '出发',
			minDate : today,
			onSelect:function(date){
				$("#startDate").val(date)
			},
			input : '#startDate'
		});
	});
	$(".zaw-btn").on("click",function(){
		if(form1.valid()){
			if ( $("#cbtest").attr("checked") ){
				$("#CM_Form").submit();
			}else{
				App.showToast("同意投保须知和保险条款");
			}
		}
	});
});